#pragma once
#include "EnermyObj.h"
#include "Environment.h"
#include "ScriptEngine.h"
#include "GameRoom.h"

EnermyObj::EnermyObj( hgeAnimation *enermy,hgeSprite *bullet,float x,float y,float time,int hp,std::string script,int bulletType) :
m_enermy(enermy),m_bullet(bullet),m_x(x),m_y(y),m_clear(false),m_hp(hp),m_conScript(script),m_time(time),m_lastfiretime(time),m_bulletType(bulletType),m_score(10*(int)sqrt((float)hp))
{
}

EnermyObj::~EnermyObj()
{

}

void EnermyObj::Update()
{
	m_clear = ScriptEngine::Compute(m_conScript.c_str(),m_time,GameRoom::getLiveTime(),this);
	m_bullMan.Update();
}

void EnermyObj::Render()
{
	m_enermy->Render(m_x,m_y);
	m_bullMan.Render();
}

hgeRect* EnermyObj::getCollision(hgeRect *rect)
{
	return (m_enermy->GetBoundingBox(m_x,m_y,rect));
}

void EnermyObj::MoveTo( float x,float y )
{
	m_x = x;
	m_y = y;
	//to be done
}

void EnermyObj::Fire(float par)
{
	m_bullMan.addBullet(new BulletInfo(m_bullet,m_x,m_y,_BULLET_WEIGHT,_BULLET_CITY,0,par,m_bulletType));
	m_lastfiretime = GameRoom::getLiveTime();
}

int EnermyObj::checkCollision( hgeRect* rect )
{
	return m_bullMan.checkCollision(rect);
}

int EnermyObj::MakeDmg( int dmg )
{
	m_hp-=dmg;
	if (m_hp<=0) 
	{
		m_clear = true;
		return m_score;
	}
	return 0;
}

bool EnermyObj::isClear()
{
	return m_clear;
}
//************************************
void EnermyObj::clearBullet()
{
	m_bullMan.clearBulllet();
}